package com.qilin.hscs.util;

import org.apache.commons.codec.binary.Hex;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by 10188 on 2018/5/2.
 */
public class MD5Util {

    public static String encrypt(String pass, String salt) {
        try {
            MessageDigest digest = MessageDigest.getInstance("sha-256");
            byte[] encyptBytes = digest.digest((pass + salt).getBytes("utf-8"));
            return Hex.encodeHexString(encyptBytes);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static boolean verify(String md5Pass,String pass, String salt) {
        if (md5Pass.equals(encrypt(pass, salt))) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(encrypt("qilinhost","qilinznjj"));
    }
}
